package com.qianyucc.blog.model.vo;

import lombok.*;
import org.springframework.data.domain.*;

import java.util.*;

/**
 * @author lijing
 * @date 2019-10-12 14:34
 * @description 封装向前端返回的分页信息
 */
@Data
public class PageInfoVO<T> {
    private List<T> data;
    private Integer totalPages;
    private Integer currentPage;
    private Long totalCount;

    public static <V> PageInfoVO<V> create(Page page, List<V> vs) {
        PageInfoVO<V> pageInfoVO = new PageInfoVO<>();
        pageInfoVO.setData(vs);
        pageInfoVO.setTotalPages(page.getTotalPages());
        pageInfoVO.setCurrentPage(page.getNumber() + 1);
        pageInfoVO.setTotalCount(page.getTotalElements());
        return pageInfoVO;
    }

    public static <V> PageInfoVO<V> create(Integer currentPage, Integer totalPages, Long totalCount, List<V> vs) {
        PageInfoVO<V> pageInfoVO = new PageInfoVO<>();
        pageInfoVO.setData(vs);
        pageInfoVO.setTotalPages(totalPages);
        pageInfoVO.setCurrentPage(currentPage);
        pageInfoVO.setTotalCount(totalCount);
        return pageInfoVO;
    }
}
